package top.lisicheng.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @author Lisicheng
 */
@Slf4j
public class Produce {

    public static void main(String[] args) {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");

        try (Connection connection = connectionFactory.newConnection("生产者");) {

            log.info("success connection");

            Channel channel = connection.createChannel();

            log.info("success create channel");

            channel.basicPublish("", "queue1", null, "hello world!".getBytes(StandardCharsets.UTF_8));

            // channel.basicPublish("direct-demo", "wx", null, "hello world!".getBytes(StandardCharsets.UTF_8));

            log.info("success publish");

        } catch (TimeoutException | IOException e) {
            log.error("error rabbitmq produce", e);
        }


    }

}
